﻿using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Sockets;

namespace Chess.Common
{
    [Serializable]
    public class NetworkClient
    {
        public NetworkClient(string clientName, TcpClient tcpClient)
        {
            ClientName = clientName;
            _tcpClient = tcpClient;
            var ep = tcpClient.Client.RemoteEndPoint as IPEndPoint;
            RemoteEp = ep;
        }

        public string ClientName { get; private set; }
        public IPEndPoint RemoteEp { get; private set; }


        private bool loggined_;

        public bool Loggined
        {
            get { return loggined_; }
            set { loggined_ = value; }
        }

        [NonSerialized]
        private TcpClient _tcpClient;

        public TcpClient TcpClient
        {
            get { return _tcpClient; }
            set { _tcpClient = value; }
        }
    }

    [Serializable]
    public class NetworkClientCollection : KeyedCollection<string,NetworkClient>
    {
        protected override string GetKeyForItem(NetworkClient item)
        {
            return item.ClientName;
        }
    }
}
